package com.bringway.global.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.bringway.global.domain.User;
import com.bringway.global.service.UserService;
import com.bringway.global.util.RequestUtils;

import net.sf.json.JSONObject;

/*
* @author qjy
* @version 创建时间：2015年9月14日 下午3:45:11
* 类说明
*/
@Controller
@RequestMapping("/user")
public class UserController extends JsonController {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping(value="/login")
	public void login(HttpServletRequest request, HttpServletResponse response) throws Exception {
		JSONObject result = new JSONObject();
		//011500203//"222222"
		String username = RequestUtils.getStringParameter(request, "username");
		String password = RequestUtils.getStringParameter(request, "password");
		User user = userService.login(username, password);
		if(null != user){
			request.getSession().setAttribute("currentUser", user);
			result.put("success", true);
		}else{
			result.put("success", false);
		}
		serialize(request, response, result);
	}

}
